﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNAControls
{
    public class Menu : XNAControl
    {
        public Texture2D Title { get; set; }
        public Texture2D Background { get; set; }
        public Texture2D[] MenuTextures { get; set; }
        public const int InitialYPosition = 265;
        public int ElementOverlapped { get; set; }

        public int MenuState { get; set; }

        public Menu()
        {
            
        }

        public int CheckElementOverlapped(Point mousePosition)
        {
            if (mousePosition.X >= Size.X / 2.0f - MenuTextures[0].Bounds.Width / 2.0f && mousePosition.X <= Size.X / 2.0f + MenuTextures[0].Bounds.Width / 2.0f)
            {
                if (mousePosition.Y >= InitialYPosition && mousePosition.Y <= InitialYPosition + MenuTextures[0].Bounds.Height * MenuTextures.Count())
                {
                    ElementOverlapped = (mousePosition.Y - InitialYPosition) / MenuTextures[0].Bounds.Height;
                    return ElementOverlapped;
                }
            }
            ElementOverlapped = -1;
            return -1;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            spriteBatch.Draw(Background, new Rectangle(Position.X, Position.Y, Size.X, Size.Y), new Color(255, 255, 255));
            spriteBatch.Draw(Title, new Vector2(Size.X / 2.0f - Title.Width / 2.0f, 35), new Color(255, 255, 255));
            if (MenuState == 0)
            {
                for (int i = 0; i < MenuTextures.Count(); ++i)
                {
                    int color = 255;
                    if (ElementOverlapped == i)
                    {
                        color = 120;
                    }
                    spriteBatch.Draw(MenuTextures[i],
                                     new Vector2(Size.X/2.0f - MenuTextures[i].Width/2.0f,
                                                 InitialYPosition + i*MenuTextures[i].Height),
                                     new Color(255, color, color));
                }
            }
        }
    }
}
